﻿using Commons.Requests;
using Commons.ReturnData;
using Microsoft.AspNetCore.Mvc;
using OpenAI.Domain.Entities;
using OpenAI.Infrastructure.Services;

namespace OpenAI.WebAPI.Controllers
{
    [ApiController]
    [Area("ChatMessage")]
    [Route("[area]/[controller]/[action]")]
    public class ChatMessageController:ControllerBase
    {
        private readonly ChatMessageService chatMessageService;
        public Guid AppUserId { get; set; }

        public ChatMessageController(ChatMessageService chatMessageService)
        {
            this.chatMessageService = chatMessageService;
        }

        [HttpGet]
        public async Task<DataResult<ChatMessage>> GetChatMessagesAsync(PagingRequest pagingRequest)
        {
            if (int.TryParse(pagingRequest.ExtendedValue1,out int cid ))
            {
                return await chatMessageService.GetChatMessagesAsync(pagingRequest,cid);
            }
            else
            {
                return new DataResult<ChatMessage>();
            }
        }

        [HttpDelete]
        public async Task<SingleResult> DeleteChatMessageAsync(int id)
        {
            return await chatMessageService.DeleteChatMessageAsync(id, AppUserId);
        }
    }
}
